<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
</head>
<body>



<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户性别</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sex" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户城市</label>
                            <div class="layui-input-inline">
                                <input type="text" name="city" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户职业</label>
                            <div class="layui-input-inline">
                                <input type="text" name="classify" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>


        <table class="layui-hide" id="currentTableId" lay-filter="employeeTableFilter"></table>



    </div>
</div>



<div id="menuAddOpen" style="display: none;">

    <div class="layui-form layuimini-form">

        <div class="layui-form-item" style="margin-top: 20px;">
            <label class="layui-form-label required">原因:</label>
            <div class="layui-input-inline">
                <input type="text" id="failMassage" lay-verify="required" lay-reqtext="原因不能为空" placeholder="请输入原因"  value="" class="layui-input ui-input-class">
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
                </div>

            </div>

        </div>
    </div>

</div>


<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/admin/operation/money',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [

                    {type: "checkbox", width: 50},
                    {field: 'checkMoneyId', width: 80, title: 'ID', sort: true},
                    {field: 'fetchPrice', width: 120, title: '提现金额'},
                    {width: 120, title: '审核状态',templet:function (res) {
                            if (res.staTus == '1') {
                                return '<span style="color: #f39c12;"> 审核中 </span>';
                            } else if (res.staTus == '0') {
                                return '<span style="color: #761c19;"> 未审核 </span>';
                            } else if(res.staTus=='2'){
                                return '<span style="color: #c00;"> 未通过 </span>';
                            }else{
                                return '<span style="color: #52C41A;"> 已通过 </span>';
                            }
                        }},
                    {field: 'createTime', width: 200, title: '创建时间'},
                    {field: 'checkTime', title: '审核时间', minWidth: 150},
                    {field: 'failMsg', width: 120, title: '原因', sort: true},
                    {field: 'remark', width: 120, title: '备注', sort: true},
                    {field: 'name', width: 80, title: '姓名'},
                    {field: 'money', width: 135, title: '金额', sort: true},
                    { width: 150, title: '类型',templet:function (res) {
                            if (res.type=='0'){
                                return '<span style="color: #0b0b0b;"> 银行卡</span>'
                            }else if (res.type=='1'){
                                return '<span style="color: #00FF00;"> 微信支付</span>'
                            } else{
                                return '<span style="color: #0000FF;">支付宝支付</span>'
                            }
                        }},
                    { align: 'center', title: '操作', width: 180, templet: OnloadTool}
                ]
            ],
            limits: [5,10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'

        });

        //判断设置按钮
        function OnloadTool(data) {
            //定义变量
            let htmls = '';
            //判断
            if (data.staTus == '0') {

                htmls+='<input type="button" class="layui-btn layui-btn-sm layui-btn layui-btn-warm" lay-event="audit" value="审核中">';

            }else if (data.staTus=='1'){
                htmls+='<input type="button" class="layui-btn layui-btn-sm layui-btn layui-btn-danger" lay-event="unreviewed" value="未通过"/>';
                htmls+='<input type="button" class="layui-btn layui-btn-sm layui-btn layui-btn-normal" lay-event="pass" value="已通过"/>';

            }else if (data.staTus=='2') {

            }else if (data.staTus=='3'){

            }
            return htmls;
        }

        //判断修改状态
        table.on('tool(employeeTableFilter)',function (data) {
                if (data.event=='unreviewed'){

                    //判断点击的按钮=
                    if ( data.event==='unreviewed'){
                        //打开弹出层
                        var pop=layer.open({
                            type:1,
                            area:['50%','50%'],
                            content:$('#menuAddOpen')
                        })
                        form.on('submit(saveBtn)',function (obj) {
                            $.ajax({
                                url:"/admin/operation/guigo.action",
                                type:"get",
                                data:{
                                    checkMoneyId:data.data.checkMoneyId,
                                    failMassage:$("#failMassage").val()
                                },
                                dataType:"text",
                                success:function (data) {
                                    table.reload('currentTableId',{
                                        url:'/admin/operation/money'
                                    })
                                    layer.close(pop);
                                }
                            })

                            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                        })

                    }
                    //

                }else if(data.event==='audit'){

                    if (data.event==='audit'){
                        $.ajax({
                            url:"/admin/operation/update",
                            type:"get",
                            //取表单的元素layui属性
                            data:{
                                checkMoneyId:data.data.checkMoneyId
                            },
                            dataType:"text",
                            success:function (res) {
                                table.reload('currentTableId',{
                                    url:'/admin/operation/money'
                                })
                            }
                        })
                    }


            }else if(data.event=='pass'){
                    //判断点击的按钮=
                    console.log(data)
                    if ( data.event==='pass'){
                        //打开弹出层
                        var pop=layer.open({
                            type:1,
                            area:['50%','50%'],
                            content:$('#menuAddOpen')
                        })
                        form.on('submit(saveBtn)',function (obj) {
                            $.ajax({
                                url:"/admin/operation/guigotow.action",
                                type:"get",
                                data:{
                                    checkMoneyId:data.data.checkMoneyId,
                                    failMassage:$("#failMassage").val()
                                },
                                dataType:"text",
                                success:function (data) {
                                    table.reload('currentTableId',{
                                        url:'/admin/operation/money'
                                    })
                                    layer.close(pop);
                                }
                            })

                            $.ajax({
                                url:"/admin/operation/fetchprice",
                                type:"get",
                                data:{
                                    checkMoneyId:data.data.checkMoneyId,
                                    fetchPrice:data.data.fetchPrice,
                                    money:data.data.money
                                },
                                dataType:"text",
                                success:function (data) {
                                    table.reload('currentTableId',{
                                        url:'/admin/operation/money'
                                    })
                                    layer.close(pop);

                                }
                            })

                            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                        })

                    }

            }else{
                $.ajax({

                    url:"/admin/operation/updatetow",
                    type:"get",
                    //取表单的元素layui属性
                    data:{
                        checkMoneyId:data.data.checkMoneyId
                    },
                    dataType:"text",
                    success:function (res) {
                        table.reload('currentTableId',{
                            url:'/admin/operation/money'
                        })
                    }
                })



            }

        });



        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);

            layer.alert(result, {
                title: '最终的搜索信息'
            });

            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });


    });

</script>


</body>
</html>
